package me.mingshan.algorithm.presum;

/**
 * @author hanjuntao
 * @date 2025/6/17 0017
 */
public class PreSumTest {
    public static void main(String[] args) {
        int[] a = {1, 2, 3, 4, 5, 6};

        int[] preSum = new int[a.length + 1];

        for (int i = 0; i < a.length; i++) {
            preSum[i+1] = preSum[i] + a[i];
        }

        // 现在求原数组的某个区间的和
        // 例如：[1,4]，需要计算出前5个元素之和并减去前1个元素之和

        System.out.println(preSum[5] - preSum[1]);
    }
}
